package com.sg.business.permission.model;

import com.sg.widgets.Widgets;
import com.sg.widgets.registry.config.Option;

public class ValidationField {

	private String fieldCode;
	private String fieldName;
	private String optionId;

	public ValidationField(String fieldCode, String fieldName, String optionId) {
		this.fieldCode = fieldCode;
		this.fieldName = fieldName;
		this.optionId = optionId;
	}

	public String getFieldCode() {
		return fieldCode;
	}

	public String getFieldName() {
		return fieldName;
	}

	public Option getOption() {
		if (optionId != null) {
			return (Option) Widgets.getOptionRegistry().getConfigurator(
					optionId);
		}
		return null;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((fieldCode == null) ? 0 : fieldCode.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ValidationField other = (ValidationField) obj;
		if (fieldCode == null) {
			if (other.fieldCode != null)
				return false;
		} else if (!fieldCode.equals(other.fieldCode))
			return false;
		return true;
	}

}
